using HarmonyLib;
using UnityEngine;
using System.Reflection;
using System;

namespace hatbox_hack
{
    [HarmonyPatch(typeof(WeaponObj))]
    public static class WeaponObjPatch
    {
        [HarmonyPatch("IsReadyToAttack")]
        [HarmonyPostfix]
        public static void IsReadyToAttackPatch(WeaponObj __instance, ref bool __result)
        {
            if (
                !(bool)Traverse.Create(__instance).Field("_isAttacking").GetValue()
                && !__instance.Inst.IsOutOfAmmo(__instance.Owner)
                && Contract.I.EnemyATKFast
                && __instance.Owner.Type == ActorType.kEnemy
            )
            {
                float recoilTime = __instance.Inst.Info.RecoilTime;
                recoilTime /= Contract.I.EnemyATKFastMultiplexer;
                __result = TimeMgr.I.GetTime() - (float)Traverse.Create(__instance).Field("_lastAttackTime").GetValue() >= recoilTime;
            }
        }
    }
}
